#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() 
{
    string s, table = "0123456789ABCDEF";
    int m,n;
    cin >> m >>n;
    
    if( m == 0)
    {
        cout << 0;
        return 0;
    }

    bool flag = false;
    if(m < 0)
    {
        m = -m;
        flag = true;
    }

    while(m != 0)
    {
        s = s+ table[m%n];
        m /= n;
    }

    if(flag == true)
    {
        s += "-";
    }
    
    reverse(s.begin(),s.end());
    cout << s << endl;
}
